package edu.ciee.tz.dao;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Component;

import edu.ciee.tz.model.Mcys;

@Component("mcysDao")
public class McysDAO {

	public List<Mcys> search(Mcys g) throws Exception {

		String query = "where 1=1";

		if (g.getId() != 0) 
			query = query + " and id like '%" + g.getId() + "%'";// this.getID()
		if (g.getMaichu_time()!= null) 
			query = query + " and maichu_time like '%" + g.getMaichu_time()+ "%'"; // this.getName()
		if (g.getYunshubg_time()!= null) 
			query = query + " and yunshubg_time like '%" + g.getYunshubg_time()+ "%'"; // this.getName()
		if (g.getYunshued_time()!= null) 
			query = query + " and yunshued_time like '%" + g.getYunshued_time()+ "%'"; // this.getName()
		if (g.getFz_person()!=null&&g.getFz_person().getId()!= 0) 
			query = query + " and fz_person like '%" + g.getFz_person().getId()+ "%'";// this.getID()
		if (g.getBuyer()!=null&&g.getBuyer().getId()!= 0) 
			query = query + " and buyer like '%" + g.getBuyer().getId()+ "%'";// this.getID()
		if (g.getTruck()!=null&&g.getTruck().getChepai()!= null) 
			query = query + " and truck like '%" + g.getTruck().getChepai()+ "%'";// this.getID()
		@SuppressWarnings("unchecked")
		List<Mcys> m_list = hibernateTemplate.find("from Mcys u "+ query);

		return m_list;
	}

	public void insert(Mcys z) throws Exception {
		this.getHibernateTemplate().save(z);
	}

	public void delete(Mcys z) throws Exception {
		this.getHibernateTemplate().delete(z);

	}

	public void update(Mcys z) throws Exception {
		this.getHibernateTemplate().update(z);
	}

	private HibernateTemplate hibernateTemplate;

	public HibernateTemplate getHibernateTemplate() {
		return hibernateTemplate;
	}

	@Resource
	public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
		this.hibernateTemplate = hibernateTemplate;
	}
}
